﻿@using Apps.Web.Core;
@using Apps.Web;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "WMS_Part";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}
<div id = "uploadExcel" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false">
<form name = "form1" method="post" id="form1">
    <table>
        <tr>
            <th style="padding:20px;"> Excel：</th>
            <td style="padding:20px;">
                <input name="ExcelPath" type="text" maxlength="255" id="txtExcelPath" readonly="readonly" style="width:200px" class="txtInput normal left">
                <a href="javascript:$('#FileUpload').trigger('click').void(0);" class="files">@Resource.Browse</a>
                <input class="displaynone" type="file" id="FileUpload" name="FileUpload" onchange="Upload('ExcelFile', 'txtExcelPath', 'FileUpload'); ">
                <span class="uploading">@Resource.Uploading</span>
                <input name="Para" type="hidden" maxlength="255" id="Para" readonly="readonly">
            </td>
        </tr>
        <tr>
            <th style="padding:20px;"> 导入状态：</th>
            <td style="padding:20px;">
                <label id="importMessage"></label>
                <a id="importResultFile" href="">         点击查看导入结果</a>
            </td>
        </tr>
    </table>
    <div class="endbtndiv">
        <a id = "btnSave" href="javascript:ImportData()" class="easyui-linkbutton btns">直接保存</a>
        <a id = "btnReturn" href="javascript:$('#uploadExcel').window('close')" class="easyui-linkbutton btnc">@Resource.Cancel</a>
    </div>
</form>
</div>
<div class="mvctool">
    @*<input id="txtPartCode" placeholder="物料编码:" type="text" class="searchText" />
        <input id="txtPartName" placeholder="物料名称:" type="text" class="searchText" />*@
    <input id="txtQuery" type="text" class="searchText" />
    @Html.ToolButton("btnQuery", "fa fa-search", Resource.Query, ref perm, "Query", true)
    @Html.ToolButton("btnCreate", "fa fa-plus", Resource.Create, ref perm, "Create", true)
    @Html.ToolButton("btnEdit", "fa fa-pencil", Resource.Edit, ref perm, "Edit", true)
    @Html.ToolButton("btnDelete", "fa fa-trash", Resource.Delete, ref perm, "Delete", true)
    @Html.ToolButton("btnImport", "fa fa-level-down", Resource.Import, ref perm, "Import", true)
    @Html.ToolButton("btnExport", "fa fa-level-up", Resource.Export, ref perm, "Export", true)
    @Html.ToolButton("btnExportTemplate", "fa fa-level-up", Resource.ExportTemplate, ref perm, "Export", true)
    @Html.ToolButton("btnSafeImport", "fa fa-level-down", "安全库存导入", ref perm, "Import", true)
    @Html.ToolButton("btnBelongCustomerImport", "fa fa-level-down", "所属客户导入", ref perm, "Import", true)
    @Html.ToolButton("btnBelongSupplierImport", "fa fa-level-down", "所属供应商导入", ref perm, "Import", true)
    @Html.ToolButton("btnVolumeImport", "fa fa-level-down", "每箱体积导入", ref perm, "Import", true)
    @Html.ToolButton("btnSafeExportTemplate", "fa fa-level-up", "安全库存模板导出", ref perm, "Export", true)
    @Html.ToolButton("btnBelongCustomerExportTemplate", "fa fa-level-up", "所属客户模板导出", ref perm, "Export", true)
    @Html.ToolButton("btnBelongSupplierExportTemplate", "fa fa-level-up", "所属供应商模板导出", ref perm, "Export", true)
    @Html.ToolButton("btnVolumeExportTemplate", "fa fa-level-up", "每箱体积模板导出", ref perm, "Export", true)
</div>
<table id="List"></table>
@Html.Partial("~/Views/Shared/_Partial_AutoGrid.cshtml")

<div id="modalwindow" class="easyui-window" style="width:800px; height:400px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
<script type="text/javascript">
    $(function () {
        $('#List').datagrid({            
            url: '@Url.Action("GetListByCode")',
            width:SetGridWidthSub(10),
            methord: 'post',
            height: SetGridHeightSub(45),
            fitColumns: true,
            sortName: 'CreateTime',
            sortOrder: 'desc',
            idField: 'Id',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            //rownumbers: true,//行号
            onLoadSuccess: function(data) {                @foreach(var r in perm){ if (r.Category == 2) { @Html.Raw("$(this).datagrid('hideColumn','" + r.KeyCode + "'); "); } }
            },
            columns: [[
                { field: 'Id', title: '物料ID', width: 80,hidden:true },
        { field: 'PartCode', title: '物料编码', width: 120,sortable:true },
                { field: 'PartName', title: '物料名称', width: 180, sortable: true },
                                { field: 'StoreMan', title: '保管员', width: 50, sortable: true },
                { field: 'PartType', title: '物料类型', width: 50,sortable:true },                 
                { field: 'CustomerCode', title: '主机厂编码', width: 180, sortable: true },          
                { field: 'LogisticsCode', title: '物流号', width: 120, sortable: true },

                //{ field: 'OtherCode', title: '额外信息编码', width: 80, sortable: true },
                //{ field: 'PCS', title: '每箱数量', width: 80,sortable:true },
                //{ field: 'Unit', title: '单位', width: 80, sortable: true },
                { field: 'Volume', title: '每箱体积', width: 60, sortable: true },
                //{ field: 'Remark', title: '说明', width: 80, sortable: true },
                { field: 'Status', title: '物料状态', width: 80, sortable: true },
                { field: 'SafeStock', title: '安全库存', width: 50, sortable: true },
                //{ field: 'CreatePerson', title: '创建人', width: 80,sortable:true },
                { field: 'BelongCustomer', title: '所属客户', width: 80,sortable:true },
                { field: 'BelongSupplier', title: '所属供应商', width: 80,sortable:true },
                //{ field: 'ModifyTime', title: '修改时间', width: 80,sortable:true }
            ]]
        });
    });
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
            $("#List").datagrid('load');
        else
            $("#List").datagrid('reload');
    }
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }
    $(function () {
        $("#btnCreate").click(function () {
            $.modalWindow(Lang.Create, '@Url.Action("Create")', 400, 440, 'fa fa-plus');
        });
        $("#btnEdit").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $.modalWindow(Lang.Edit, '@Url.Action("Edit")?id=' + row.Id + '&Ieguid=' + GetGuid(), 400, 440, 'fa fa-pencil');
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
        });
        $("#btnDetails").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $.modalWindow(Lang.Details, '@Url.Action("Details")?id=' + row.Id + '&Ieguid=' + GetGuid(), 700, 400, 'fa fa-list');
            } else { $.messageBox5s(Lang.Tip, Lang.PleaseSelectTheOperatingRecord); }
	        });
        $("#btnQuery").click(function () {
            //var partCode = $("#txtPartCode").val();
            //var partName = $("#txtPartName").val();
            //if (partCode == null) {
            //    partCode = "";
            //}
            //if (partName == null)
            //{
            //    partName = "";
            //}
            //$("#List").datagrid("load", { partCode: partCode, partName: partName });
            var queryStr = $("#txtQuery").val();
            if (queryStr == null) {
                queryStr = "%";
            }
            $("#List").datagrid("load", { queryStr: queryStr });

        });
        $("#btnDelete").click(function () {
	            dataDelete("@Url.Action("Delete")", "List");
	        });
        $("#btnImport").click(function() {
            $("#txtExcelPath").val("")
            $("#Para").val("0")
            $("#uploadExcel").window({ title: '@Resource.Import', width: 450, height: 210, iconCls: 'fa fa-level-down' }).window('open');
        });
        $("#btnSafeImport").click(function() {
            $("#txtExcelPath").val("")
            $("#Para").val("1")
            $("#uploadExcel").window({ title: '@Resource.Import', width: 450, height: 210, iconCls: 'fa fa-level-down' }).window('open');
        });
        $("#btnBelongCustomerImport").click(function() {
            $("#txtExcelPath").val("")
            $("#Para").val("2")
            $("#uploadExcel").window({ title: '@Resource.Import', width: 450, height: 210, iconCls: 'fa fa-level-down' }).window('open');
        }); 
        $("#btnBelongSupplierImport").click(function() {
            $("#txtExcelPath").val("")
            $("#Para").val("3")
            $("#uploadExcel").window({ title: '@Resource.Import', width: 450, height: 210, iconCls: 'fa fa-level-down' }).window('open');
        });
        $("#btnVolumeImport").click(function() {
            $("#txtExcelPath").val("")
            $("#Para").val("4")
            $("#uploadExcel").window({ title: '@Resource.Import', width: 450, height: 210, iconCls: 'fa fa-level-down' }).window('open');
        });
        $("#btnExport").click(function() {
            var queryStr = $("#txtQuery").val();
            if (queryStr == null) {
                queryStr = "%";
            }
          $.post("@Url.Action("CheckExportData")?queryStr=" + queryStr, function(data) {
                if (data.type == 1)
                {
                    window.location = "@Url.Action("Export")?queryStr=" + queryStr;
                }
                else
                {
                $.messageBox5s(Lang.Tip, data.message);
                }
            }, "json");
        });
        $("#btnExportTemplate").click(function() {
          window.location = "@Url.Action("ExportTemplate")";
        });
        $("#btnSafeExportTemplate").click(function() {
          window.location = "@Url.Action("ExportSafeTemplate")";
        });
        $("#btnBelongCustomerExportTemplate").click(function() {
          window.location = "@Url.Action("ExportBelongCustomerTemplate")";
        }); 
        $("#btnBelongSupplierExportTemplate").click(function() {
          window.location = "@Url.Action("ExportBelongSupplierTemplate")";
        });
        $("#btnVolumeExportTemplate").click(function() {
          window.location = "@Url.Action("ExportVolumeTemplate")";
        });
    });
    function ImportData()
    {
        showLoading();
        var para = $("#Para").val();
        if (para == 0) {
            var url = "@Url.Action("Import")?filePath="+$("#txtExcelPath").val();
        }
        if (para == 1) {
            var url = "@Url.Action("SafeStockImport")?filePath="+$("#txtExcelPath").val();
        }
        if (para == 2) {
            var url = "@Url.Action("BelongCustomerImport")?filePath="+$("#txtExcelPath").val();
        } 
        if (para == 3) {
            var url = "@Url.Action("BelongSupplierImport")?filePath="+$("#txtExcelPath").val();
        }
        if (para == 4) {
            var url = "@Url.Action("VolumeImport")?filePath="+$("#txtExcelPath").val();
        }
        @*else {
            var url = "@Url.Action("SafeStockImport")?filePath="+$("#txtExcelPath").val();
        }*@
        $.post(url, function(data) {
            if (data.type == 1)
            {
                $("#List").datagrid('load');
                $('#uploadExcel').window('close');
                $('#FileUpload').val('');
            }
            hideLoading();
            $.messageBox5s('提示', data.message);
            $('#importMessage').html(data.message);
            $('#importResultFile').attr('href', data.value);
        }, "json");
    }
</script>

